package interfaces.spawnMenu.costumize.items;

import interfaces.spawnMenu.AbsSpawnMenu;

import java.util.List;

import fileHandling.language.Lang;
import fileHandling.language.interfaces.SpawnMenuText;

import logic.items.ItemProperties;
import logic.items.ItemType;
import logic.ships.equipmentListener.EquipmentListener;
import logic.ships.equipmentListener.ItemChangedEvent;
import logic.ships.equipmentListener.WeaponChangedEvent;
import logic.ships.hunter.Hunter;

public class ItemBuyContent extends BuyableContent<ItemProperties> {
	
	public ItemBuyContent(int width, int height, Hunter hunter, AbsSpawnMenu spawnMenu) {
		super(width, height, hunter);
		
		spawnMenu.addListener(hunter, new EquipmentListener() {
			@Override
			public void itemUsed(ItemChangedEvent event) {
				infoContent.updateAmount(getBoughtAmount(event.getItem().getProperties()));
			}
			
			@Override
			public void itemRemoved(ItemChangedEvent event) {
				infoContent.updateAmount(getBoughtAmount(event.getItem().getProperties()));
			}
			
			@Override
			public void itemAdded(ItemChangedEvent event) {
				infoContent.updateAmount(getBoughtAmount(event.getItem().getProperties()));
			}
			
			@Override
			public void weaponRemoved(WeaponChangedEvent event) {}
			@Override
			public void weaponAdded(WeaponChangedEvent event) {}
		});
	}
	
	@Override
	protected List<ItemProperties> getBuyableList() { return hunter.getTeam().getItemPropList(); }
	
	@Override
	protected int getBoughtAmount(ItemProperties settings) {
		return getItemsAmount(settings.getType());
	}
	
	protected int getItemsAmount(ItemType type) {
		return hunter.getItemsAmount(type);
	}
	
	@Override
	protected void buyItem(ItemProperties settings) {
		hunter.addItem(settings);
	}
	
	@Override
	protected void sellItem(ItemProperties settings) {
		hunter.removeItem(settings.getType());
	}
	
	@Override
	protected Lang getBuyButtonText() { return SpawnMenuText.Buy_Item; }
	
	@Override
	protected Lang getSellButtonText() { return SpawnMenuText.Sell_Item; }
}